from django.db import models
from django.contrib.auth.models import User



      
class QuestionManager(models.Manager):
    # get areas
    def get_areas(self):
        return All_Questions.objects.values_list('area', flat=True).distinct()
    

class All_Questions(models.Model):
    title = models.CharField(max_length=150)
    area = models.CharField(max_length = 150)
    image = models.CharField(max_length=50, null=True)
    times_used = models.IntegerField(max_length=50, default=0)
    times_incorrect = models.IntegerField(max_length=50, default=0)
    correct_percentage = models.IntegerField(max_length=10, default=0)
    objects = QuestionManager()
    
    def __unicode__(self):
        return self.title
    
    def is_multiselect(self):
        if (self.correct_answers_set.count() > 1):
            return True
        else:
            return False
    
    def __unicode_id__(self):
        return u'%s'(self.id)
     
class User_Data(models.Model):
    user = models.ForeignKey(User)
    question = models.ForeignKey(All_Questions)
    times_used = models.IntegerField(max_length=50, default=0)
    times_incorrect = models.IntegerField(max_length=50, default=0)
    correct_percentage = models.IntegerField(max_length=10, default=0)

class All_Answers(models.Model):
    question = models.ForeignKey(All_Questions)
    answer = models.CharField(max_length=100, null=True)
    
class Correct_Answers(models.Model):
    question = models.ForeignKey(All_Questions)
    answer = models.ForeignKey(All_Answers)
    
class Staging(models.Model):
    area = models.CharField(max_length=50, null=True)
    question = models.CharField(max_length=500, null=True)
    answer_1 = models.CharField(max_length=450, null=True)
    answer_2 = models.CharField(max_length=450, null=True)
    answer_3 = models.CharField(max_length=450, null=True)
    answer_4 = models.CharField(max_length=450, null=True)
    answer_5 = models.CharField(max_length=450, null=True)
    answer_6 = models.CharField(max_length=450, null=True)
    answer_7 = models.CharField(max_length=450, null=True)
    answer_8 = models.CharField(max_length=450, null=True)
    image = models.CharField(max_length=450, null=True)
    correct_answer_1 = models.CharField(max_length=50, null=True)
    correct_answer_2 = models.CharField(max_length=50, null=True)
    correct_answer_3 = models.CharField(max_length=50, null=True)
    correct_answer_4 = models.CharField(max_length=50, null=True)
    

        
    
